package com.example.validatestudy.demos.algorithm.exercise;

import java.util.Arrays;
import java.util.HashMap;

/**
 * 
 * 力扣第一题：两数之和
 * https://leetcode.cn/problems/two-sum/description/?utm_source=LCUS&utm_medium=ip_redirect&utm_campaign=transfer2china
 *  
 * */ 

public class OneTest{
	
	public static void main(String[] args){
		int[] arr = {3,3};

		int[] r =  one(arr,6);
		System.out.println(Arrays.toString(r));
	}

	public static int[] one(int[] arr,int target){

		HashMap<Integer,Integer> map = new HashMap();
		int[] result = new int[2];
		for (int i = 0; i < arr.length; i++) {
			int num = target - arr[i];
			if(map.containsKey(num)){
				result[0] = i;
				result[1] = map.get(num);
			}else{
				map.put(arr[i],i);
			}
		}
		return result;
	}

}

